package com.lovo.service.impl;

import com.lovo.bean.RoleInfoBean;
import com.lovo.dao.IRoleInfoDAO;
import com.lovo.service.IRoleInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author bdk
 * @since 2021-03-05
 */
@Service
@Transactional(rollbackFor = Throwable.class)
public class RoleInfoServiceImpl extends ServiceImpl<IRoleInfoDAO, RoleInfoBean> implements IRoleInfoService {
    @Resource
    private IRoleInfoDAO roleInfoDAO;
    @Override
    public List selectRoleIdsByUserId(Long userId) {
        return roleInfoDAO.selectRoleIdsByUserId(userId);
    }

    @Override
    public void deleteById(Long roleId) {
        roleInfoDAO.deleteFromUserRoleByRoleId(roleId);
        roleInfoDAO.deleteFromFunctionRoleByRoleId(roleId);
        roleInfoDAO.deleteById(roleId);
    }

    @Override
    public void addFunctionRole(Long roleId, List<Long> funcIds) {
        roleInfoDAO.deleteFromFunctionRoleByRoleId(roleId);
        for(Long funcId:funcIds){
            roleInfoDAO.insertFunctionRole(roleId,funcId);
        }
    }
}
